<template>
  <div class="exception">
    <div class="img">
      <img :src="config[type].img"/>
    </div>
    <div class="content">
      <h1>{{ config[type].title }}</h1>
      <div class="desc">{{ config[type].desc }}</div>
      <div class="action">
        <a-button type="primary" @click="handleToHome">{{ $t('logOut') }}</a-button>
      </div>
    </div>
  </div>
</template>

<script>
import types from './type'
import { mapActions } from 'vuex'
import {ACCESS_TOKEN} from "@/store/mutationTypes";

export default {
  name: 'Exception',
  props: {
    type: {
      type: String,
      default: '404'
    }
  },
  data () {
    return {
      config: types
    }
  },
  methods: {
    ...mapActions(['Logout']),
    handleToHome () {
      this.Logout().then(() => {
        if (process.env.NODE_ENV === 'development'){
          location.href = location.origin + '#' + '/user/login?redirect=' + this.$route.fullPath
        }else {
          /*const token = sessionStorage.getItem(ACCESS_TOKEN)
          if (token) {
            sessionStorage.removeItem(ACCESS_TOKEN)
          }*/
          sessionStorage.clear();
          //TODO 配置化
          location.href = process.env.VUE_APP_SSO_BASE_URL+"/idp/authCenter/GLO?redirectToLogin=true&redirectToUrl="+process.env.VUE_APP_HOME_BASE_URL
        }
        window.location.reload()
        // 从403登出的时候 回到最原始的登录地址 不要记忆之前的redirect
       // location.href = location.pathname + '#' + '/user/login'
       // window.location.reload()
      })
    }
  }
}
</script>

<style lang="less" scoped>
  .exception {
    min-height: 500px;
    height: 80%;
    align-items: center;
    text-align: center;
    margin-top: 150px;
    .img {
      display: inline-block;
      padding-right: 52px;
      zoom: 1;
      img {
        height: 360px;
        max-width: 430px;
      }
    }
    .content {
      display: inline-block;
      flex: auto;
      h1 {
        color: #434e59;
        font-size: 7.2rem;
        font-weight: 600;
        line-height: 72px;
        margin-bottom: 24px;
      }
      .desc {
        color: rgba(0, 0, 0, .45);
        font-size: 2rem;
        line-height: 28px;
        margin-bottom: 16px;
      }
    }
  }

  .mobile {
    .exception {
      margin-top: 30px;
      .img {
        padding-right: unset;

        img {
          height: 40%;
          max-width: 80%;
        }
      }
    }
  }
</style>
